package com.zoro.barn.inner.service.documentsql.sql.controller;

import com.zoro.barn.api.documentsql.sql.BarnSqlService;
import com.zoro.barn.dto.documentsql.sql.SqlQueryDto;
import com.zoro.barn.inner.service.documentsql.sql.service.SqlInfoService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoxingwu
 */
@RestController
@RequestMapping("sql-query")
public class BarnSqlServiceController implements BarnSqlService {


    private final SqlInfoService sqlInfoService;

    public BarnSqlServiceController(SqlInfoService sqlInfoService) {
        this.sqlInfoService = sqlInfoService;
    }

    @Override
    public SqlQueryDto queryProjectSql(SqlQueryDto dto) {

        Integer result = this.sqlInfoService.countByProject(dto.getProjectId());
        SqlQueryDto count = new SqlQueryDto();
        count.setSqlCount(result == null ? 0 : result);
        return count;
    }

    @Override
    public SqlQueryDto queryProductSql(SqlQueryDto dto) {
        Integer result = this.sqlInfoService.countByProduct(dto.getProductId());
        SqlQueryDto count = new SqlQueryDto();
        count.setSqlCount(result == null ? 0 : result);
        return count;
    }
}
